package course.dmsSpringBoot.controller;

/**
 * @author zouran
 * createDate：2023/12/5  16:12
 */

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
@CrossOrigin
@RestController
@RequestMapping("/a")
public class test {
    @PostMapping("/b")
    public String saveArticleImagesTypora(@RequestParam("file") MultipartFile file,@RequestParam("project") String project) throws IOException {
        String filename= file.getOriginalFilename();
        String extName = null;
        if (filename != null) {
            extName = filename.substring(filename.lastIndexOf('.'));
        }
        String fileName =System.currentTimeMillis()+ extName;
        String fileFullName = "D:\\Data\\"+project+"\\"+ fileName;
        File localFile = new File(fileFullName);
        File parentFile = localFile.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        file.transferTo(localFile);
        // nginx地址
        return "https://file.zouran.top/markdown/" +project+"/"+ fileName;
    }
}
